var loading = false;
var app = new Vue({
    el: '#app',
    data: {
        cityId: 0,
        userId: 0,
        listTab: '',
        sendContent: '',
        listData: [],
        hideing: true,
        moreName: ['正在加载'],
        pageIndex: 1,
        pageSize: 10,
    },
    created() {
        FastClick.attach(document.body);
        this.cityId = $.getPara('cityId');
        if (this.cityId) {
            if ($.getPara("userId") != "") {
                this.userId = parseInt($.getPara("userId"));
                $.setStorage("userId", this.userId)
            } else {
                if ($.getStorage("userId") && $.getStorage("userId") != "") {
                    var userId = parseInt($.getStorage("userId"));
                    this.userId = userId
                }
            }
            this.getListcomments()
        } else {
            $.toast('没有获取城市所在的ID', 'text')
        }
    },
    mounted() {
        var that = this;
        this.$nextTick(function() {
            $(document.body).infinite().on("infinite", function() {
                if (loading)
                    return;
                loading = true;
                that.hideing = false;
                setTimeout(function() {
                    var pageIndex = that.pageIndex;
                    pageIndex++;
                    that.pageIndex = pageIndex;
                    that.getData();
                    loading = false
                }, 1500)
            })
        })
    },
    methods: {
        backTop() {
            window.history.go(-1)
        },
        getListcomments: function(pageIndex, pageSize) {
            var that = this;
            $.ajax({
                url: '/api/activity/substation/list',
                type: 'get',
                data: {
                    cityId: this.cityId,
                    pageIndex: this.pageIndex,
                    pageSize: this.pageSize,
                },
            }).done(function(res, status, xhr) {
                if (res.code == 200) {
                    var list = res.data.list;
                    if (list.length > 0) {
                        var original = that.listData;
                        var array = original.concat(list);
                        that.listData = array
                    } else {
                        loading = true
                    }
                    that.hideing = true
                } else {
                    $.toast(res.msg, "text")
                }
            })
        },
        urlHref(item) {
            var para = {};
            para.title = "活动详情";
            para.type = "topic";
            para.url = '/PageClassify/html/Substation/activityDetails.html?id=' + item.id + "&cityId="+this.cityId;
            if (this.userId > 0) {
                para.url = '/PageClassify/html/Substation/activityDetails.html?id=' + item.id + "&userId=" + this.userId + "&cityId="+this.cityId;
            }
            if (/(Android)/i.test(navigator.userAgent)) {
                jsAndroid.appPush(JSON.stringify(para))
            } else if (/(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent)) {
                window.webkit.messageHandlers.appPush.postMessage(para)
            } else {
                window.location.href = para.url;
                alert("PC浏览器")
            }
        }
    }
})
